﻿@inject IHttpService _httpService


<CnGalWebSite.Components.Containers.MasaTitleContainer Icon="@GetIcon()" Title="@(Model.PublishPlatformType== PublishPlatformType.Other&&string.IsNullOrWhiteSpace(Model.PublishPlatformName)==false?Model.PublishPlatformName:Model.PublishPlatformType.GetDisplayName())"
Class="entry-card-default store-info-card mb-4">
    @if (Model.StoreInfor.State != StoreState.None&& Model.Time != null && Model.Time.Value.Date <= DateTime.Now.ToCstTime().Date)
    {
        <div itemprop="offers" itemscope itemtype="https://schema.org/Offer">
            @if (Model.StoreInfor.PriceNow > 0)
            {
                <span class="ma-1 d-flex">
                    <CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaIcon Type="IconType.Price" />
                    <span class="me-1">当前价格：¥</span>
                    @if (Model.StoreInfor.CutNow > 0)
                    {
                        <s class="me-1">@(Model.StoreInfor.OriginalPrice.Value.ToString(" 0.00"))</s>
                    }
                    <span> @(Model.StoreInfor.PriceNow.Value.ToString("0.00") + (Model.StoreInfor.CutNow >0 ? " - 折扣 " + Model.StoreInfor.CutNow + "%" : ""))</span>
                </span>
                @if (Model.StoreInfor.CutLowest > 0)
                {
                    <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.Chart" Text="@("历史最低：¥ " + Model.StoreInfor.PriceLowest.Value.ToString("0.00") + (Model.StoreInfor.CutLowest > 0 ? " - 折扣 " + Model.StoreInfor.CutLowest + "%" :"" ))" Class="ma-1" />
                }
            }
            else if (Model.StoreInfor.PriceNow == 0)
            {
                <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.Free" Text="当前价格：¥ 0.00 - Free" Class="ma-1" />

            }
            else if (Model.StoreInfor.State == StoreState.NotPublished && Model.Type!= GameReleaseType.Demo)
            {
                <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.State" Text="未发售" Class="ma-1" />
                <meta itemprop="availability" content="PreOrder" />
            }
            else if (Model.StoreInfor.State == StoreState.Takedown)
            {
                <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.Takedown" Text="已下架" Class="ma-1" />
                <meta itemprop="availability" content="SoldOut" />
            }
            else if (Model.StoreInfor.PriceNow == null)
            {
                @if (Model.StoreInfor.OriginalPrice > 0)
                {
                    <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.Price" Text="@("价格：¥ " + Model.StoreInfor.OriginalPrice.Value.ToString("0.00") + "（数据未更新）")" Class="ma-1" />
                }
                else if (Model.StoreInfor.OriginalPrice == 0)
                {
                    <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.OutOfDate" Text="价格：¥ 0.00 - Free（数据未更新）" Class="ma-1" />
                }
                else
                {
                    <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.OutOfDate" Text="数据未更新" Class="ma-1" />
                }
                <meta itemprop="availability" content="SoldOut" />
            }

            @if (Model.StoreInfor.PlayTime > 0)
            {
                <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.DeterminedTime" Text="@($"平均游玩时长：{Model.StoreInfor.PlayTime/60.0:0.0} 小时")" Class="ma-1" />
            }

            @if (Model.StoreInfor.EstimationOwnersMax > 0 && Model.StoreInfor.EstimationOwnersMin > 0)
            {
                @if (Model.StoreInfor.EstimationOwnersMax== Model.StoreInfor.EstimationOwnersMin)
                {
                    <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.Users" Text="@($"拥有人数（估计）：{Model.StoreInfor.EstimationOwnersMin:#,#}")" Class="" />
                }
                else
                {
                    <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.Users" Text="@($"拥有人数（估计）：{Model.StoreInfor.EstimationOwnersMin:#,#} - {Model.StoreInfor.EstimationOwnersMax:#,#}")" Class="" />
                }
            }

            @if (Model.StoreInfor.OriginalPrice >= 0)
            {
                <meta itemprop="priceCurrency" content="CNY" />
                <meta itemprop="price" content="@(Model.StoreInfor.OriginalPrice)" />
            }
        </div>
    }
    <div>
        @if (string.IsNullOrWhiteSpace(Model.Link) == false)
        {
            <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.Link" Text="链接：" Url="@Model.GetLink()" Class="ma-1" ItemProp="url" />
        }
        @if (string.IsNullOrWhiteSpace(Model.Name) == false)
        {
            <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.Name" Title="发行名称" Text="@Model.Name" Class="ma-1" />
        }
        @if (string.IsNullOrWhiteSpace(Model.TimeNote))
        {
            @if (Model.Time != null)
            {
                <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.IndeterminateTime" Title="发行时间" Text="@(Model.Time.Value.ToString("yyyy年M月d日"))" Class="ma-1" />
            }
        }
        else
        {
            <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.DeterminedTime" Title="发行时间" Text="@Model.TimeNote" Class="ma-1" ItemProp="datePublished" />
        }
        @if (Model.GamePlatformTypes.Any())
        {
            <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.Game" Title="游戏平台" Text="@string.Join("、", Model.GamePlatformTypes.Select(s=>s.GetDisplayName()))" Class="ma-1" />
        }
        @if (string.IsNullOrWhiteSpace(Model.Engine) == false)
        {
            <CnGalWebSite.Shared.MasaComponent.Shared.Components.IconText Icon="@IconType.Engine" Title="引擎" Text="@Model.Engine" Class="ma-1" />
        }

        <TypeChip Model="Model" />
        <TimeChip Model="Model" />
        <EvaluationChip Model="Model" />
    </div>
</CnGalWebSite.Components.Containers.MasaTitleContainer>

@code {

    [Parameter]
    public GameReleaseViewModel Model { get; set; }


    public string GetIcon()
    {
        return Model.PublishPlatformType switch
        {
            PublishPlatformType.Steam => "mdi-steam",
            PublishPlatformType.AppStore => "mdi-apple",
            PublishPlatformType.GooglePlay => "mdi-google-play",
            _ => "mdi-pine-tree"
        };
    }
}
